//滚动条分页
(function (w, cw) {
    var Scroll = function (data) {
        this.Init(data);
        return this;
    }, c,page = 2;
    Scroll.prototype = {
        Init: function (data) {
            c = this;
            var nextData = {url:data.url,native:false};
            this.paint(data.id);
            this.c = new iScroll(data.id, { "useTransition": true, "vScrollbar": false, "hScroll": false,
                "onScrollStart": function () {

                }, "onScrollEnd": function () {//this.y
                    //(this.maxScrollY + " " + this.y);
                    if(c.nextPage){
                        $("#pull_up_label").text("上拉加载更多");
                        c.nextPage = false;
                        nextData.url = data.url + "/" + page;
                        netWork(nextData,data.method);
                        page++;
                    }
                }, "onScrollMove": function () {
                    if(Math.abs(this.y) - Math.abs(this.maxScrollY) > 20 || this.maxScrollY > 0){
                        if(c.noPage)return;
                        $("#pull_up_label").text("松开刷新");
                        c.nextPage = true;
                    }
                }, "onTouchEnd": function () {

                }
            });
        },
        paint: function(id){//基本元素架构
            var htm = "<div id = 'scroller'>" +
                "<ul id = 's_content'></ul>"+
                "<div id='pullUp'><span id = 'pull_up_label'></span></div>"+
                "</div>";
            $("#"+id).html(htm);
        },
        //getData: function(data){
        //    var html = "",date;
        //    data.data.forEach(function(item){
        //        date = new Date(item.time);
        //        html += "<li>"+
        //            "<img src='"+item.images+"'>"+
        //            "<div class = 'left ell'><span class = 'name'>"+item.nickName+"</span><br><span class = 'address'>"+item.roomUnit+"</span></div>"+
        //            "<div class = 'right ell'><span class = 'activity-time'>"+formatTime(date)+"</span><br><span class = 'reward'>"+item.prize+"</span></div>"+
        //            "</li>";
        //    });
        //    c.add(html);
        //    c.refresh();
        //},
        add: function(html){
            $("#s_content").append(html);
            $("#pull_up_label").text("上拉加载更多");
        },
        destroy: function () {
            if (this.c) this.c.destroy();
            this.c = null;
        },
        scrollToElement: function (select, time) {//滚动到某个元素
            if (this.c) this.c.scrollToElement(select, time);
        },
        scrollTo: function (x, y, min) {
            if (this.c) this.c.scrollTo(x, y, min);
        },
        refresh: function(){
            if (this.c) this.c.refresh();
        },
        nextPage: false,
        noPage: false
    };
    cw.Scroll = Scroll;
})(window, cw);